$(function () {

        var productstock_datagrid = $("#productstock_datagrid");
        
        //商品即时库存列表初始化-begin
        $("#productstock_datagrid").datagrid({
            fit: true,
            url: "/productstock/list",
            fitColumns: true,
            pagination: true,
            singleSelect: true,
            rownumbers: true,
            striped: true,
            toolbar: "#tb",
            //取出多个商品对象中的值
            loadFilter: function(data){
        		if (data.rows){
        			for(var i=0;i<data.rows.length;i++){
        				data.rows[i].productName = data.rows[i].product.name;
        				data.rows[i].depotName = data.rows[i].depot.name;
        				data.rows[i].productSn =data.rows[i].product.sn;
        				data.rows[i].remark =data.rows[i].product.remark;
        				data.rows[i].brandName =data.rows[i].product.brandName;
        				data.rows[i].expirationDate =data.rows[i].product.expirationDate;
        				data.rows[i].unit =data.rows[i].product.unit;
        			}
        			return data;
        		}
            },
            columns: [[
                
                {field: "id", title: "编号", hidden: true},
                {field: "depotName", title: "仓库名称", width: 100},
                {field: "productName", title: "商品名称", width: 100},
                
                {field: "productSn", title: "商品编码", width: 100},
                
                {field: "price", title: "商品进价", width: 100},
                
                {field: "brandName", title: "商品品牌", width: 100},
                
                {field: "unit", title: "库存", width: 100},
                
                {field: "remark", title: "商品备注", width: 100},
                
                {field: "expirationDate", title: "过期时间", width: 100, sortable: true, order: 'desc'},
                
                {field: "amount", title: "库存汇总", width: 100}
            ]]

        })
        
        //商品列表初始化-end
        
    
        //统一管理响应函数
        var cmdObj = {
            //顶部工具栏的刷新
        	reload : function(){
        		productstock_datagrid.datagrid("load");
        		
        	},
              	
            
            //顶部工具栏:高级查询
            query: function () {
                //获取查询参数
                var kw = $("#keyword").textbox("getValue");
                var dt = $("#depot").combobox("getValue");
                var brand = $("#brand").combobox("getValue");
                var limitNumber = $("#limitNumber").textbox("getValue");
                var maxNumber = $("#maxNumber").textbox("getValue");
                //表格加载时顺带一起传递查询参数
                productstock_datagrid.datagrid("load", {
                    keyword: kw,
                    depotId: dt ? dt : -1,
                    id: brand ? brand : -1,
                    limitNumber : limitNumber,
                    maxNumber : maxNumber
                })
            },
                                  
        } //end

        
        //调用cmdObj
        $("a[data-cmd]").click(function () {
            var cmd = $(this).data('cmd');
            cmdObj[cmd]();
        })

    }
)